<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/8
 * Time: 下午4:00
 */

use kartik\datetime\DateTimePicker;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\ActiveForm;


?>
<?php
$paraString = explode('?', Yii::$app->request->url)[1];
?>
<?php
$category = \common\models\CouponCategory::find()->select('id,title')->asArray()->all();
$categoryList = [];
if (count($category) > 0) {
    foreach ($category as $v) {
        $categoryList[$v['id']] = $v['title'];
    }
}
?>
<div class="user-coupon-index">
    <h1><?= Html::encode($this->title) ?></h1>
    <?php $form = ActiveForm::begin([
        'method' => 'get',
        'options'=> ['class'=>'form-inline'],
    ]); ?>

    <?= $form->field($model, 'mobile')->textInput()->label("手机号") ?>
    <?= $form->field($model, 'catalog')->dropDownList(['' => '全部'] + $categoryList) ?>
    <?= $form->field($model, 'startTime')->widget(DateTimePicker::classname(),
        ['options' => ['placeholder' => '开始时间'],
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd',
                'inline' => true,
            ]
        ])->label("开始时间");
    ?>

    <?= $form->field($model, 'endTime')->widget(DateTimePicker::classname(),
        ['options' => ['placeholder' => '开始时间'],
            'pluginOptions' => [
                'autoclose' => true,
                'todayHighlight' => true,
                'format' => 'yyyy-mm-dd',
                'inline' => true,
            ]
        ])->label("结束时间");
    ?>

    <div id="search-option">
        <?= Html::submitButton('搜索', ['class' => 'btn btn-primary center']) ?>
        <?= Html::a('同步领取数据', ['sync'],['class' => 'btn btn-primary center']) ?>
    </div>
    <?php ActiveForm::end(); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute' => '券号',
                'value' => function ($model) {
                    return $model->coupon->code;
                }
            ],
            [
                'attribute' => '手机号',
                'value' => function ($model) {
                    return $model->user->phone;
                }
            ],
//            [
//                'attribute' => 'catalog',
//                'value' => function ($model) {
//                    return $model->couponCategory->name;
//                }
//            ],
            [
                'attribute' => 'created_at',
                'value' => function ($model) {
                    return date("Y-m-d H:i:s", $model->created_at);
                }
            ],
            [
                'attribute' => 'updated_at',
                'value' => function ($model) {
                    return date("Y-m-d H:i:s", $model->updated_at);
                }
            ],
            ['class' => 'yii\grid\ActionColumn',
                'template' => '{delete}'
            ],

        ],
    ]); ?>
</div>